package org.example;

public class Main {
    public static void main(String[] args) {

        // [3,9,20,null,null,15,7],
        TreeNode treeNode = new TreeNode(6);

        treeNode.left = new TreeNode(7);
        treeNode.left.left = new TreeNode(9);
        treeNode.left.right = new TreeNode(8);

        treeNode.right = new TreeNode(7);
        treeNode.right.left = new TreeNode(8);
        treeNode.right.right = new TreeNode(9);

        Main main = new Main();

        System.out.println(main.isSymmetric(treeNode));
    }
    public boolean isSymmetric(TreeNode root) {
        return root == null || recur(root.left, root.right);
    }
    boolean recur(TreeNode L, TreeNode R) {
        // 判断两个节点是否相等，如果两个节点都为空，则返回true，
        if (L == null && R == null) return true;
        // 如果两个节点有一个为空或者值不相等，则返回false，
        if (L == null || R == null || L.val != R.val) return false;
        // 否则返回递归判断两个节点的左右子树是否相等的结果
        return recur(L.left, R.right) && recur(L.right, R.left);
    }

}